package com.ft.core.utils.validate.impl;

import com.ft.core.utils.validate.NotNullAndEmpty;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @copyright (C), 2015-2019, XXX有限公司
 * @fileName: NotNullAndEmptyValidatorImpl
 * @author: 李阳
 * @date: 2019/5/14 11:10
 * @description: 不可为Null或空实现
 * @history: <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
public class NotNullAndEmptyValidatorImpl implements ConstraintValidator<NotNullAndEmpty, Object> {

    @Override
    public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
        if (o instanceof List) {
            return ((List) o).size() > 0;
        }
        if (o instanceof String) {
            return o.toString().length() > 0;
        }

        return  o instanceof Long ||
                o instanceof Integer || o instanceof BigDecimal ||
                o instanceof Boolean || o instanceof Double || o instanceof Float ||
                o instanceof Enum || o instanceof Date;
    }
}
